import classifyPoint from 'robust-point-in-polygon'

export function outArea(obj, area) {
  let polygon = area.map(item=>[item.x, item.y])
  return getInOut(polygon, [obj.x, obj.y]) === "outside"
}

export function inArea(obj, area) {
  let polygon = area.map(item=>[item.x, item.y])
  let result = getInOut(polygon, [obj.x, obj.y]) 
  return result === "inside" || result === "boundary"
}

export function getInOut(polygon, point) {
  let claim
  let result = (classifyPoint(polygon, point))
  if (result === -1) {
    claim = "inside"
  }
  if (result === 0) {
    claim = "boundary"
  }
  if (result === 1) {
    claim = "outside"
  }
  return claim
}
